<template xmlns="http://www.w3.org/1999/html">
  <div class="content">
    <div class="title">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><b>系统</b></el-breadcrumb-item>
        <el-breadcrumb-item>经销商管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="main-content">
      <el-form :inline="true">
        <el-input v-model="condition" placeholder="法人姓名/经销商名称/手机号" style="width: 200px"></el-input>
        <el-form-item>
          <el-button type="primary" @click="queryAgency">查询</el-button>
          <el-button @click="add" type="primary">新增</el-button>
        </el-form-item>
      </el-form>
      
        <el-table :data="agencyList" highlight-current-row @expand="expandRow" fit="true">
          <el-table-column type="expand">
            <template scope="props">
              <el-form label-position="left" inline class="demo-table-expand" >
                <el-form-item label="经销商名称">
                  <span>{{ expandContent.dealerName }}</span>
                </el-form-item>
                 <el-form-item label="经销商简称">
                  <span>{{expandContent.abbreviation }}</span>
                </el-form-item>
                <el-form-item label="法人姓名">
                  <span>{{ expandContent.legalPersonName }}</span>
                </el-form-item>
                <el-form-item label="经销商地址">
                  <span>{{ expandContent.address }}</span>
                </el-form-item>
                <el-form-item label="法人身份证号">
                  <span>{{ expandContent.legalPersonIdcard }}</span>
                </el-form-item>
                <el-form-item label="联系电话">
                  <span>{{ expandContent.phone }}</span>
                </el-form-item>
                <div v-for="(bank,index) in banks">
                  <el-form-item label="银行名称">
                    {{index+1}}:
                    <span>{{ bank.name }}</span>
                  </el-form-item>
                  <el-form-item label="银行账号">
                    {{index+1}}:
                    <span>{{ bank.card }}</span>
                  </el-form-item>
                </div>
                <el-form-item label="经销商类别">
                  <span>{{ expandContent.dealerTypeName }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="dealerId" label="经销商ID" width="120" v-if="false">
          </el-table-column>
          <el-table-column prop="dealerName" label="经销商名称" width="250">
          </el-table-column>
          <el-table-column prop="legalPersonName" label="法人姓名" width="220" >
          </el-table-column>
          <el-table-column prop="phone" label="联系电话" width="250">
          </el-table-column>
          <el-table-column prop="options" label="操作" min-width="150">
            <template scope="scope">
              <el-button @click="change(scope.$index,scope.row)" type="text" size="small">修改</el-button>
              <el-button @click="deleteRow(scope.$index,scope.row)" type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
  
        <el-pagination layout="sizes,prev, pager, next" @current-change="getCurrentPage"
                       :page-sizes="[10,20,30,50]" :total="total"
                       :page-size="pagesize"
                       :current-page.sync="currentPage"
                       @size-change="sizeChange"
                       style="text-align: center;margin-top: 20px">
        </el-pagination>
     
    </div>
  </div>
</template>

<script>
  import ElCol from 'element-ui/packages/col/src/col'
  import ElForm from '../../../node_modules/element-ui/packages/form/src/form.vue'
  import axios from 'axios'
  import $ from 'jquery'

  export default {
    components: {
      ElForm,
      ElCol},
    data () {
      return {
        banks:[{name:'',card:''}],
        expandContent:{},
        condition:'',
        companyNo:sessionStorage.getItem('companyNo'),
        deptOptions:[],
        agencyList:[],
        pagesize: 10,
        currentPage:1,
        total: 10,
        recive:[],
      }
    },
    methods:{
      expandRow(row,expanded){
        this.expandContent={}
        this.banks=[]
        let that = this
        
        if(expanded){
          this.$http.get("/dealer/detail/"+row.dealerId)
          .then((response)=>{
            var bankList=[]
            this.expandContent=response.data.data
            if(response.data.data.dealerType=='0'){
              this.expandContent.dealerTypeName="集团内"
            }else{
              this.expandContent.dealerTypeName="集团外"
            }
            $.each(response.data.data.dealerAccountVOS,function(index,value){
              bankList.push({name:value.bankName,card:value.bankCard})
            })
            that.banks = bankList
          })
          .catch(function(error){
            console.log(error)
          })
        }
      },

      getAgencyList(key){
        this.$http.get("/dealer/list",{
          params:{
            key:key,
            pageSize:this.pagesize,
            pageNo:this.currentPage
          }
        })
        .then((response)=>{
          this.agencyList=response.data.data
        })
        .catch(function(error){
          console.log(error)
        })
      },

      deleteRow(index,row){
        this.$http.delete('/dealer/'+row.dealerId)
        .then((response)=>{
          if(response.data.success){
            this.$message("删除成功")
            this.getAgencyList()
          }else{
            this.$message("删除失败")
          }
        })
        .catch(function(error){
          console.log(error)
        })
      },

      getCurrentPage:function (currentPage) {
        this.currentPage = currentPage;
        this.getAccount();
      },

      queryAgency(){
        this.getAgencyList(this.condition)
      },

      sizeChange(val){
        this.pagesize=val;
        this.getAccount();
      },

      add:function () {
        this.$router.push({path:'/backgroundManaSys/addagency'})
      },

      change(index, row){
        this.$router.push({path:'/backgroundManaSys/addagency',query:{content:row.dealerId}})
      }

    },

    mounted() {
      this.getAgencyList('')
    },
  }
</script>

<style lang="scss" scoped>
 .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
.content {
  padding: 10px;
  background: #F7F7F7;
  .title {
    color: #99A9BF;
    font-size: 14px;
    line-height: 18px;
    margin: 8px 0px 10px 0px;
  }
  .main-content {
    background: #fff;
    position: fixed;
    top: 96px;
    bottom: 10px;
    left: 216px;
    right: 16px;
    overflow: auto;
    padding: 20px;
  }
}
</style>
